package com.apestech.framework.config;

import com.apestech.framework.util.StringUtil;
import com.apestech.framework.util.modul.ClassMethod;
import org.dom4j.Element;

/**
 * @author hup
 * @create 2018-12-06-9:40
 */
public class SourceConfig extends StringUtil{

    private ClassMethod method;
    private Element node;

    public SourceConfig(ClassMethod method, Element node) throws Exception {
        if(method==null) throw new Exception("请检查代码：传入类名信息是否为合法的！");
        this.method=method;
        this.node=node;
        init();
    }

    private void init(){
        int len=method.getCount();
        for(int i=0; i<len; i++){
            String key=method.getKeylist().get(i);
            String smethod=method.getField("G_"+key).getMethodName();
            Object obj=method.getAccess().invoke(method.getExecclass(), smethod);
            node.addAttribute(key, castToString(obj));
            //System.out.println("key:"+key+" method:"+smethod+" value:"+obj);
        }
    }

}
